package com.gen;

import com.baomidou.mybatisplus.generator.config.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.TemplateConfig;
import com.baomidou.mybatisplus.generator.config.builder.CustomFile;
import com.gen.config.MbpGeneratorConfig;
import com.dto.BizBaseItemDto;
import com.entity.BizBaseItemEntity;
import com.service.BizBaseItemServiceImpl;
import com.service.IBizBaseItemService;
import com.vo.BizBaseItemVo;

import java.util.*;

/**
 * @author: Cxx
 * @Version 1.0
 * @create: 2025-10-01 21:32
 * @description:
 **/
public class MbpGeneratorItem extends MbpGenerator {

    public MbpGeneratorItem(MbpGeneratorConfig config) {
        super(config);
    }

    @Override
    public void strategyConfigAfter(StrategyConfig.Builder builder) {
        builder
                .entityBuilder().superClass(BizBaseItemEntity.class)
                .serviceBuilder()
                .superServiceClass(IBizBaseItemService.class)
                .superServiceImplClass(BizBaseItemServiceImpl.class);
    }

    @Override
    public List<String> getTableNames() {
        return getConfig().getItemTableNames();
    }

    @Override
    public void injectionConfig(InjectionConfig.Builder builder) {
        Map<String, Object> customMap = new HashMap<>();
        customMap.put("dtoPackageName", getConfig().getParent() + ".dto");
        customMap.put("dtoSuperClass", BizBaseItemDto.class.getCanonicalName());

        customMap.put("voPackageName", getConfig().getParent() + ".vo");
        customMap.put("voSuperClass", BizBaseItemVo.class.getCanonicalName());
        builder.customMap(customMap);

        List<CustomFile> customFiles = new ArrayList<>();
        customFiles.add(new CustomFile.Builder().packageName("dto").fileName("DTO.java")
                .templatePath("/templates/dto.java.vm").enableFileOverride().build()
        );
        customFiles.add(new CustomFile.Builder().packageName("vo").fileName("VO.java")
                .templatePath("/templates/vo.java.vm").enableFileOverride().build()
        );

        builder.customFile(customFiles);
    }

}
